<template>
  <ContentCard>
    <PageHeaderNew title="申请中心" :breadCrumb="breadCrumb" />
    <a-tabs lazy-load>
      <a-tab-pane :key="1" title="申请中心">
        <ApprovalCards />
      </a-tab-pane>
      <a-tab-pane :key="2" title="我的发起">
        <table-turn :table-data="getTableData" ref="tableRef">
          <a-table-column :width="80">
            <template #title> 序号 </template>
            <template #cell="{ rowIndex }">
              {{ rowIndex + 1 }}
            </template>
          </a-table-column>
          <a-table-column title="名称">
            <template #cell="{ record }">
              {{ record.approvalTitle }}
            </template>
          </a-table-column>
          <a-table-column title="状态" data-index="last">
            <template #cell="{ record }">
              {{ record.currentApprovalResult }}
            </template>
          </a-table-column>
          <a-table-column
            :width="120"
            data-index=""
            title="操作"
            fixed="right"
            align="center"
          >
            <template #cell="{ record }">
              <a-button type="text" @click="huandle(record)">
                <template #default>审批</template>
              </a-button>
            </template>
          </a-table-column>
        </table-turn>
      </a-tab-pane>
    </a-tabs>
  </ContentCard>
</template>
<script setup lang="ts">
import type { ApprovalReleaseParams } from '@/apis/approvalExecute/type';
import TableTurn, { type paramsType } from '@/components/TableTurn/index.vue';
import {
  getApprovalReleaseList,
  getApprovalReleaseByApprovalCode
} from '@/apis/approvalExecute/index';
import ApprovalCards from './components/ApprovalCards.vue';
import { useRouter } from 'vue-router';
const router = useRouter();
const breadCrumb = ['申请中心'];
const releaseApproval = reactive({ list: [] });
const releaseApprovalParams = reactive<ApprovalReleaseParams>({
  appCode: 'APP280373000',
  userId: 2,
  queryType: 3
});
const getTableData = async (params: paramsType) => {
  try {
    const res = await getApprovalReleaseList({
      ...params,
      ...releaseApprovalParams
    });
    return Promise.resolve(res);
  } catch (error: unknown) {
    console.log(error);
  }
};
const huandle = (data: any) => {
  router.push({
    name: 'ApprovalDetails',
    query: { approvalCode: data.approvalCode }
  });
};
</script>
